#ifndef THREAD_H
#define THREAD_H


#include <QMutex>
#include <QWaitCondition>
#include"overallsituation.h"

void terminateProcessByPath(const QString& processPath);

// 任务类型
class Task
{

public:
    int Indet;  //标识
    int ParentID;//父协议
    int SubID;//子协议
    QJsonObject Data;//数据值

public:
    Task();
    ~Task();
    void execute(int index);
};

// 执行线程
class WorkThread : public QThread
{
    Q_OBJECT // Add Q_OBJECT macro here
public:
    WorkThread();
    WorkThread(class ThreadPool *parent);
    ~WorkThread();
protected:
    virtual void run();


private:
    class ThreadPool *m_Pool;

    Qt::HANDLE m_Handle;
        Task *task;
};

// 线程池
class ThreadPool : public QObject
{
    Q_OBJECT
public:
    ThreadPool();
    explicit ThreadPool(int count, QObject *parent = nullptr);
    ~ThreadPool();

    void PushTask(ThreadInfo threadinfo);
    void PushTask(ThreadInfo threadinfo,bool IsNotEmpty);
    void Start(QString threadname);
    void Destroy();
    void a();



private:
    QList<ThreadInfo> m_Tasks;                             // 任务队列
    QList<QSharedPointer<WorkThread>> m_Threads;      // 运行的线程
    bool m_bStop;                                    // 停止线程
    QString Name;

    QTimer* timer;
    QMutex m_TaskMutex;
    QWaitCondition m_NotEmpty;

    friend class WorkThread;
};



#endif // THREAD_H
